<?php

/**
 * IndexController - The default controller class
 * 
 * @author
 * @version 
 */

require_once 'Zend/Controller/Action.php';

class Administrator_PaypalController extends Zend_Controller_Action 
{
	

	public function init(){
		

		
	}
	
	public function preDispatch()
	{
		
		$this->getHelper ('layout')->setLayout('framelayout');
		
		$this->view->addHelperPath(MY_ROOT.'/vhelpers');
		
		Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');
		
		$member=new CMember();
		
		if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())){
			
			$this->_redirect(MY_URL.'/administrator-auth-login');
			
			return false;
			
		}
		
		return true;
		
	}
	
	public function cancelAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$accountid=$this->_request->getParam('accountid');
		
		$account=new CAccount();
		
		$account->delAccount(array($accountid));
		
		$this->view->showMsg("取消该退款成功!",'administrator-account-item');
		
	}
	
	public function dopayAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$confirmAccount=$this->_request->getParam('confirmAccount');
		
		$accountid=$this->_request->getParam('accountid');
		
		$account=new CAccount();
			
		$accountArray=$account->getDetail($accountid);
		
		if($accountArray[0]['state']=='1'){
			
			$this->view->showMsg("对该退款请求之前已经退过款了!");
			
		}else{
			
			$paramArray=$this->_request->getParams();
		   		
	   		$filters = array(
	    		'*'   => 'StringTrim'
			);
	
			$validators = array(
			);
			
			$input = new Zend_Filter_Input($filters, $validators, $paramArray);
			
			$content=$input->content?$input->content:'';
		
			$account->editAccount($accountid,array('state'=>'1','has_paid'=>$confirmAccount));
			
			if($input->payment=='coupon'){
		   		
		   		$mycoupon=new CCoupon();
			
				$mycoupon->addCoupon($confirmAccount,"WHERE uid='".$accountArray[0]['from_uid']."'");
		   		
		   	}	
		   	
			$data=array(
		   					'should_paid'=>$accountArray[0]['should_paid'],
		   					'has_paid'=>$confirmAccount,
		   					'flid'=>3,
		   					'state'=>1,
		   					'orderid_string'=>$accountArray[0]['orderid_string'],
		   					'from_uid'=>0,
		   					'to_uid'=>$accountArray[0]['from_uid'],
							'payment'=>$input->payment,
		   					'add_time'=>time(),
							'remark'=>$content
		   					);
		   					
		   	$account->createAccount($data);		   	
		   	
		   	$this->view->showMsg("成功退款!");
		
		}
	   	
	}
 
   	
	public function postAction(){
	
		//$this->_helper->viewRenderer->setNoRender();
		
		//$this->getHelper ('layout')->disableLayout ();
	
	}
    

    
}
